package com.chainyoung.trademarket.mvp.presenter;

import com.chainyoung.common.appcommon.entity.CommonList;
import com.chainyoung.common.base.CommonSubscriber;
import com.chainyoung.common.di.scope.FragmentScope;
import com.chainyoung.common.exception.ApiException;
import com.chainyoung.common.mvp.BasePresenter;
import com.chainyoung.common.utils.RxUtils;
import com.chainyoung.component_tmtrade.bean.FiatOrder;
import com.chainyoung.trademarket.di.module.FindData;
import com.chainyoung.trademarket.entity.Ad;
import com.chainyoung.trademarket.mvp.contract.AdDetailContract;
import com.chainyoung.trademarket.mvp.contract.FindContract;

import java.util.TreeMap;

import javax.inject.Inject;

import static com.chainyoung.common.constant.LibConstant.NO_RESULT_ERRORCODE;


@FragmentScope
public class FindPresenter extends BasePresenter<FindContract.Model, FindContract.View> {

    @Inject
    public FindPresenter(FindContract.Model model, FindContract.View rootView) {
        super(model, rootView);
    }


    public void getFindData() {

        addSubscribe(mModel.getFindData()
                .compose(RxUtils.<FindData>rxSchedulerHelper())
                .subscribeWith(new CommonSubscriber<FindData>(mView) {
                    @Override
                    public void onNext(FindData data) {
                        mView.onGetDataSuccess(data);
                    }

                    @Override
                    public void onError(Throwable e) {
                        if (e instanceof ApiException) {
                            if (((ApiException) e).getErrorCode().equals(NO_RESULT_ERRORCODE)) {
                                mView.onGetDataSuccess(null);
                                return;
                            }
                        }
                        mView.onGetDataFailed();
                        super.onError(e);
                    }
                }));
    }


}
